package casa.depesos.app.com.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhpan.bannerview.BaseBannerAdapter;
import com.zhpan.bannerview.BaseViewHolder;

import casa.depesos.app.com.R;
import casa.depesos.app.com.http.data.Banner;
import casa.depesos.app.com.it.BannerClickListener;

public class BannerAdapter extends BaseBannerAdapter<Banner> {

    BannerClickListener listener;
    boolean showTv;

    public BannerAdapter(BannerClickListener listener) {
        this(listener, false);
    }

    public BannerAdapter(BannerClickListener listener, boolean showTv) {
        this.listener = listener;
        this.showTv = showTv;
    }

    @Override
    protected void bindData(BaseViewHolder holder, Banner data, int position, int pageSize) {
        View item = holder.findViewById(R.id.root);
        ImageView img = (ImageView) holder.findViewById(R.id.img);
        Glide.with(img).load(data.img).into(img);
        if (showTv) {
            TextView tv = (TextView) holder.findViewById(R.id.tv);
            tv.setVisibility(View.VISIBLE);
            tv.setText(data.getMsg());
        }
        holder.itemView.setOnClickListener(view -> {
            if (listener != null) {
                listener.onBannerClick(data);
            }
        });
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.banner_item;
    }
}
